Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
How can I remove ":" from the elements of array

I am Trying to convert the array [ '9:00', '9:40', '9:50', '11:00', '15:00', '18:00' ] to [ '900', '940', '950', '1100', '1500', '1800' ] in javascript.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can do it in this way:-

let oldArray = ['9:00', '9:40', '9:50', '11:00', '15:00', '18:00'];
let newArray = oldArray.map(elem => elem.replace(':',''));
console.log(newArray);
about 4 years ago · Juan Pablo Isaza Report

0

What you're looking for is the .map() function. This function iterates over all items in the array, allowing you to execute code on said iterations. Use what I've provided below.

const arrayOfTimestamps = [ '9:00', '9:40', '9:50', '11:00', '15:00', '18:00' ];

const formattedTimestamps = arrayOfTimestamps.map(time => time.replace(/:/g, ''))

As an explanation, .map() iterates over each item, and the time is being handled by regex. the /g aka global flag tells the regex to remove all semicolors's from the strings.

For more information on how .map() works, here.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

about 4 years ago · Juan Pablo Isaza Report

0

Although there are other solutions that use less lines of code, the following is easier to read. Loop through your list of dates and for each date, replace the colon character with a blank.

var list = [ '9:00', '9:40', '9:50', '11:00', '15:00', '18:00' ];

for (var i = 0; i < list.length; i++)
{
  list[i] = list[i].replace(':', ''); 
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!